#ifndef SUDOKUBOARD_H
#define SUDOKUBOARD_H

#include <QWidget>
#include <QGridLayout>
#include <QVector>
#include <array>
#include "SudokuCell.h"

class SudokuBoard : public QWidget
{
    Q_OBJECT

public:
    explicit SudokuBoard(QWidget *parent = nullptr);
    
    void initializeBoard(const QVector<QVector<int>>& puzzle, 
                        const QVector<QVector<int>>& solution);
    bool checkSolution();
    bool isComplete() const;
    void setLevelDifficulty(int difficulty);
    void clearBoard();
    void resetBoard();
    
    int getCellValue(int row, int col) const;
    void setCellValue(int row, int col, int value);
    QVector<QVector<int>> getCurrentState() const;
    
    static const int BOARD_SIZE = 9;

signals:
    void cellValueChanged(int row, int col, int value);
    void puzzleSolved();
    void puzzleCompleted();

private slots:
    void onCellValueChanged(int row, int col, int value);

private:
    void setupUI();
    bool isValidPlacement(int row, int col, int value) const;
    void updateCellAppearance();
    
    QGridLayout *m_gridLayout;
    std::array<std::array<SudokuCell*, BOARD_SIZE>, BOARD_SIZE> m_cells;
    QVector<QVector<int>> m_solution;
    QVector<QVector<int>> m_initialPuzzle;
    QVector<QVector<int>> m_currentState;
    int m_difficulty;
};

#endif